package com.qidianit.task.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.task.mapper.ProjectMapper;
import com.qidianit.task.mapper.TaskMapper;
import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/9/5 下午 4:43
 */
@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    private TaskMapper taskMapper;
    @Override
    public QdResult selectByPage(Project project, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.selectList(project);
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }

    @Override
    public void deleteByProjectId(String projectId) {
        projectMapper.deleteByProjectId(projectId);
    }

    @Override
    public Project selectOneByProjectId(String projectId) {
        return projectMapper.selectOneByProjectId(projectId);
    }

    @Override
    public void saveProject(Project project){
        projectMapper.saveProject(project);
    }

    @Override
    public void pigeonholeProject(String projectID){
        projectMapper.pigeonholeProject(projectID);
    }

    @Override
    public void publishProject(List<String> projectIds){
        projectMapper.publishProject(projectIds);
    }

    @Override
    public void batchPigProject(List<String> projectIds) {
        projectMapper.batchPigProject(projectIds);
    }

    @Override
    public void batchDelProject(List<String> projectIds) {
        projectMapper.batchDelProject(projectIds);
    }

    @Override
    public void recoverProject(String projectId) {
        projectMapper.recoverProject(projectId);
    }

    @Override
    public void batchRecoverProject(List<String> projectIds) {
        projectMapper.batchRecoverProject(projectIds);
    }

    @Override
    public QdResult selectDelList(Project project, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.selectDelList(project);
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }

    @Override
    public QdResult getProjectById(String projectId) {
        return QdResult.success(projectMapper.getProjectById(projectId));
    }

    @Override
    public Long sumTaskNum(String projectId) {
        return taskMapper.sumTaskNum(projectId);
    }

    @Override
    public QdResult countProject(Long userId) {
        Long countProjectNum = projectMapper.countProject();
        Long countProjectByUserId = projectMapper.countProjectByUserId(userId);
        Long countNotOkTask = projectMapper.countMyNotOKTaskNotOK(userId);
        Long countOkTask = projectMapper.countMyOKTask(userId);
        List<Long> allCount = new ArrayList<>();
        allCount.add(countProjectNum);
        allCount.add(countProjectByUserId);
        allCount.add(countNotOkTask);
        allCount.add(countOkTask);
        return QdResult.success(allCount);
    }

}
